package cn.cj.erp.common.redis;

import cn.cj.erp.common.exception.ServiceException;
import cn.hutool.core.util.StrUtil;

/**
 * Redis key 前缀枚举
 *
 * @author jianchen
 * @version 1.0.0
 * @date 2024/8/1
 */
public enum RedisKeyEnum {
    SYSTEM_CONFIG("system:config:", "系统配置"),
    REQUEST_ID("request:id:", "请求id"),
    SERVER_INFO("server:info:", "服务器信息"),
    LOGIN_TOKEN("login:token:", "登录token"),
    LOGIN_CAPTURE("login:captcha:", "验证码"),
    LOGIN_ERROR_PASSWORD("login:error:password:", "输错密码次数"),
    ;

    private final String prefix;
    private final String label;

    RedisKeyEnum(String prefix, String label) {
        this.prefix = prefix;
        this.label = label;
    }

    public String getPrefix() {
        return prefix;
    }

    public String getLabel() {
        return label;
    }

    public String getKey(Object key) {
        if (key == null) {
            throw new ServiceException("redis key can't be empty");
        }
        return this.getPrefix() + key;
    }
}